﻿//  Copyright (c) 2011 Ray Liang (http://www.dotnetage.com)
//  Licensed MIT: http://www.opensource.org/licenses/mit-license.php

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DNA.Mvc.Community
{
    public class ForumStat
    {
        private IForumContext forumContext;

        public ForumStat(IForumContext context)
        {
            this.forumContext = context;
            TotalForums = context.Forums.Count();
            TotalThreads = context.Threads.Count(t => t.IsApproved && !t.IsDeleted);
            TotalPosts = context.Posts.Count(t => t.IsApproved && !t.IsDeleted);
            var start=DateTime.Today;
            var end=start.AddHours(24);
            TodayPosts = context.Posts.Count(t => t.IsApproved && !t.IsDeleted && t.Posted>=start && t.Posted<=end);
            TodayPosts = context.Threads.Count(t => t.IsApproved && !t.IsDeleted && t.Posted >= start && t.Posted <= end);
        }

        public int TotalForums { get; private set; }

        /// <summary>
        /// Gets/Sets the total threads of the forums.
        /// </summary>
        public int TotalThreads { get; private set; }

        /// <summary>
        /// Get/Sets the total posts of the forums.
        /// </summary>
        public int TotalPosts { get; private set; }

        /// <summary>
        /// Gets/Sets the total posts of today.
        /// </summary>
        public int TodayPosts { get; private set; }

        /// <summary>
        /// Gets/Sets the total threads of today.
        /// </summary>
        public int TodayThreads { get; private set; }
    }
}
